#include "stdafx.h"
#include "Exhaustion.h"
#include <iostream>
#include <string>
using namespace std;


Exhaustion::Exhaustion(Counter * c)
{
	this->c = c;
	this->s = new string();
}

void Exhaustion::doExh(int *d)
{
	char c('+');
	int i = 0;
	bool b = false;
	for (int i1 = 0; i1 < 4; i1++)
		for (int i2 = 0; i2 < 4; i2++)
			for (int i3 = 0; i3 < 4; i3++)
				for (int i4 = 0; i4 < 4; i4++)
				{
					char _c[32];
					s->clear();
					_itoa(d[0], _c, 10);
					s->append(_c);
					s->append(1, *getSymbol(i1, &c));
					_itoa(d[1], _c, 10);
					s->append(_c);
					s->append(1, *getSymbol(i2, &c));
					_itoa(d[2], _c, 10);
					s->append(_c);
					s->append(1, *getSymbol(i3, &c));
					_itoa(d[3], _c, 10);
					s->append(_c);
					s->append(1, *getSymbol(i4, &c));
					_itoa(d[4], _c, 10);
					s->append(_c);
					//cout << s->c_str() <<"    "<< ++i<< endl;
					//cout << *getSymbol(i1, &c) << endl;
					
					display(s, d[5],b);

				}
	if (!b)
	{
		cout << "none" << endl;
	}
}


Exhaustion::~Exhaustion()
{
	delete s;
}

char* Exhaustion::getSymbol(const int & i, char *c)
{
	//char c;
	switch (i)
	{
	case 0:
		*c = '+';
		break;
	case 1:
		*c = '-';
		break;
	case 2:
		*c = '*';		
		break;
	case 3:
		*c = '/';
		break;
	}
	return c;
}

void Exhaustion::display(const string * s,int &i,bool &b)
{
	if (i == c->coutn(*s))
	{
		b = true;
		cout << *s << " =" << i << endl;
	}
		
}
